//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/.
// 			VisualNovelToolkit		     /_/_/_/_/_/.
// Copyright ©2013 - Sol-tribe.	/_/_/_/_/_/_/_/_/_/.
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/.

using UnityEngine;
using System.Collections;

namespace ViNoToolkit{
	
	/// <summary>
	/// Button base.
	/// </summary>
	public class ButtonBase : UIBase {
		#region Setup in inspector

		public bool activeAtStart = true;

		// the Event Receiver. this is usually "EventManager" object.
		public GameObject eventReceiver;

		// SendMessage function name.
		public string sendMessage;

		// with string ?.
		public string paramString = "";

		// GameObject.Find( ) and Send Message ? if found.
		public bool findObjectAndSendMessage;

		// the target object name.
		public string targetObjectName;

		// Cached transform.
		protected Transform m_TransformCache;
		public enum TouchResponse{
			OFFSET=0,
			SCALE,
			NONE,
		}

		public TouchResponse touchResponse = TouchResponse.OFFSET;
		public bool animate = true;
		public Vector3 offsetAmount = new Vector3( 2f , -2f , 0f );
		public Vector3 scaleAmount = new Vector3( 1.2f , 1.2f , 1f );

		public bool animateColor;

		[Range(0f , 10f)]
		public float durationOfColor = 0.5f;

		public Color focusColor = Color.green;
		public Color normalColor = Color.white;
		public AudioClip clickSound;
		
		#endregion

		protected AudioSource clickSoundAudioSource;
		
		static protected Vector3 m_TouchBeganAmount;
		static protected GameObject m_TouchedObject;
		static protected TouchResponse m_TouchObjectResponse;

		/// <summary>
		/// Raises the mouse enter event.
		/// </summary>
		void OnMouseEnter( ){
			if( animateColor ){
				SetHoverColor( durationOfColor ); 
			}
		}

		/// <summary>
		/// Raises the mouse exit event.
		/// </summary>
		void OnMouseExit( ){
			if( animateColor ){
				SetNormalColor( durationOfColor ); 
			}
		}

		public override void OnEnabled( ){
			if( animateColor ){
				SetNormalColor( 0f ); 
			}			
		}

		public override void OnStart(){
			m_TransformCache = transform;
			if( ! activeAtStart ){
				gameObject.SetActive( false );
			}
		}

		protected void ResetBeganAmount( Transform resetTra ){
			switch( m_TouchObjectResponse ){
				case TouchResponse.OFFSET:
					resetTra.localPosition	= m_TouchBeganAmount;
					iTween.MoveTo( m_TouchedObject, iTween.Hash("position", m_TouchBeganAmount, "islocal", true, "time", 1f ));	
					break;

				case TouchResponse.SCALE:
					resetTra.localScale = m_TouchBeganAmount;
					iTween.ScaleTo( m_TouchedObject , m_TouchBeganAmount , 1f );
					break;

				case TouchResponse.NONE:	break;
			}
		}
	}

}